package com.yonyou.crm.common.enumeration.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.yonyou.crm.common.biz.service.BaseBizServiceImpl;
import com.yonyou.crm.common.enumeration.entity.EnumVO;
import com.yonyou.iuap.context.InvocationInfoProxy;

@Service
public class EnumBizServiceImpl extends BaseBizServiceImpl<EnumVO> {

	public List<Map<String, Object>> getEnumByCode(String code) {
		Map<String, Object> paraMap = new HashMap<String, Object>();
		paraMap.put("code", code);
		return dao.selectList(EnumVO.class, "getEnumByCond", paraMap);
	}

	public Map<String, List<EnumVO>> getEnumByCodes(String[] codes) {
		
		Map<String, List<EnumVO>> resultMap = new HashMap<String, List<EnumVO>>();
		
		Map<String, Object> paraMap = new HashMap<String, Object>();
		paraMap.put("codes", codes);
		paraMap.put("tenantId", new Long(InvocationInfoProxy.getTenantid()));
		
		List<Map<String, Object>> searchList = dao.selectList(EnumVO.class, "getEnumByCodes", paraMap);
		for (Map<String, Object> map : searchList) {
			
			String code = (String) map.get("code");
			@SuppressWarnings("unchecked")
			List<EnumVO> voList =  (List<EnumVO>) map.get("enum");
			resultMap.put(code, voList);
		}

		return resultMap;
	}
	
	public Object getEnumByValue(String code, Integer value) {
		Map<String, Object> paraMap = new HashMap<String, Object>();
		paraMap.put("code", code);
		paraMap.put("value", value);
		paraMap.put("tenantId", new Long(InvocationInfoProxy.getTenantid()));
		
		return dao.selectOne(EnumVO.class, "getEnumByCond", paraMap);
	}
	
	public List<Map<String, Object>> selectFieldsByIds(String code, Object[] values) {
		
		Map<String, Object> paraMap = new HashMap<String, Object>();
		paraMap.put("code", code);
		paraMap.put("ids", values);
		paraMap.put("tenantId", new Long(InvocationInfoProxy.getTenantid()));
		return dao.selectList(EnumVO.class, "selectFieldsByIds", paraMap);
	}
}
